package 贪心andDp;

import java.util.Arrays;
import java.util.Scanner;

public class _07最优装载问题 {
    /**
     * 给出n个物体，第i个物体重量为wi。选择尽量多的物体，使得总重量不超过C。
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] wi = new int[n];
        for (int i = 0 ; i < n;i++){
            wi[i]=sc.nextInt();
        }
        int C = sc.nextInt();
        Arrays.sort(wi);
        int ans = f(n,wi,C);
        System.out.println(ans);
    }

    private static int f(int n, int[] wi, int c) {
        int sum = 0;
        int cnt = 0;
        for (int i = 0 ; i < n ;i++){
            sum += wi[i];
            if (sum<=c){
                cnt++;
            }else {
                break;
            }
        }
        return cnt;
    }
}
